/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-01-06
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-02-07
 * @Description: 滚动列表项
 */
import 'package:flutter/material.dart';
import 'c_square_avatar.dart'; // 头像组件

// 自定义 ListTile 用于展示功能相关信息，如设置、朋友圈等
Widget customListFunction({
  required String title,
  required IconData icon,
  required Color? iconColor,
}) {
  return ListTile(
    title: Text(
      title,
      style: const TextStyle(fontWeight: FontWeight.w500),
    ),
    leading: Icon(
      icon,
      color: iconColor,
    ),
    trailing: const Icon(Icons.chevron_right),
  );
}

// 自定义 ListTile 用于展示聊天相关，如朋友、群聊等
Widget customListInfo({
  required String title, // 标题
  String? subtitle, // 子标题
  IconData? icon, // 图标
  String? imageUrl, // 头像图片地址
  Color backgroundColor = Colors.amber, // 头像背景颜色
  size = 40, // 头像大小
  trailing, // 右侧图标
  onTap, // 点击事件
}) {
  return ListTile(
    title: Text(
      title,
      overflow: TextOverflow.ellipsis,
      style: const TextStyle(fontWeight: FontWeight.w500),
    ),
    subtitle: subtitle != null
        ? Text(
            subtitle,
            overflow: TextOverflow.ellipsis,
            style: const TextStyle(color: Colors.grey),
          )
        : null, // 仅在有传入 subtitle 时才显示
    leading: CustomSquareAvatar(
      icon: icon,
      imageUrl: imageUrl,
      size: size,
      backgroundColor: backgroundColor,
    ),
    trailing: trailing,
    onTap: onTap,
  );
}

Widget customUserInfo({
  required String title, // 标题
  String? subtitle, // 子标题
  IconData? icon, // 图标
  String? imageUrl, // 头像图片地址
  Color backgroundColor = Colors.amber, // 头像背景颜色
  double size = 40, // 头像大小
  Widget? trailing, // 右侧图标
  void Function()? onTap, // 点击事件
}) {
  return GestureDetector(
    onTap: onTap,
    child: Padding(
      padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
      child: Row(
        children: [
          // 头像部分
          CustomSquareAvatar(
            icon: icon,
            imageUrl: imageUrl,
            size: size,
            backgroundColor: backgroundColor,
          ),
          const SizedBox(width: 16), // 头像和文字之间的间隔

          // 文字部分
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  title,
                  overflow: TextOverflow.ellipsis,
                  style: const TextStyle(fontWeight: FontWeight.w500),
                ),
                if (subtitle != null)
                  Text(
                    subtitle,
                    overflow: TextOverflow.ellipsis,
                    style: const TextStyle(color: Colors.grey),
                  ),
              ],
            ),
          ),

          // 右侧图标
          if (trailing != null) ...[
            const SizedBox(width: 8),
            trailing,
          ],
        ],
      ),
    ),
  );
}
